package com.kh.rationaldrugreview.neo4j.service;

import com.kh.rationaldrugreview.neo4j.entity.DrugNode;
import com.kh.rationaldrugreview.neo4j.repository.DrugNodeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class DrugKnowledgeService {
    
    private final DrugNodeRepository drugNodeRepository;
    
    public List<DrugNode> findAllDrugs() {
        return drugNodeRepository.findAll();
    }
    
    public Optional<DrugNode> findDrugByCode(String drugCode) {
        return drugNodeRepository.findByDrugCode(drugCode);
    }
    
    public List<DrugNode> searchDrugsByName(String drugName) {
        return drugNodeRepository.findByDrugNameContaining(drugName);
    }
    
    public List<DrugNode> findDrugsByActiveIngredient(String activeIngredient) {
        return drugNodeRepository.findByActiveIngredientContaining(activeIngredient);
    }
    
    public List<DrugNode> findDrugsByCategory(String category) {
        return drugNodeRepository.findByCategory(category);
    }
    
    public List<DrugNode> findInteractingDrugs(String drugCode) {
        return drugNodeRepository.findInteractingDrugs(drugCode);
    }
    
    public Object findInteractionBetweenDrugs(String drugCode1, String drugCode2) {
        return drugNodeRepository.findInteractionBetweenDrugs(drugCode1, drugCode2);
    }
    
    public List<DrugNode> findDrugsContraindicatedFor(String condition) {
        return drugNodeRepository.findDrugsContraindicatedFor(condition);
    }
    
    public List<DrugNode> findDrugsForIndication(String indication) {
        return drugNodeRepository.findDrugsForIndication(indication);
    }
    
    public List<Object> findInteractionsBySeverity(String severity) {
        return drugNodeRepository.findInteractionsBySeverity(severity);
    }
    
    public List<DrugNode> findDrugsByExactActiveIngredient(String ingredient) {
        return drugNodeRepository.findDrugsByExactActiveIngredient(ingredient);
    }
    
    public DrugNode saveDrugNode(DrugNode drugNode) {
        return drugNodeRepository.save(drugNode);
    }
    
    public void deleteDrugNode(Long id) {
        drugNodeRepository.deleteById(id);
    }
    
    /**
     * 添加药品适应症关系
     */
    public void addIndicationRelationship(String drugName, String indication) {
        drugNodeRepository.addIndicationRelationship(drugName, indication);
    }
    
    /**
     * 添加药品禁忌症关系
     */
    public void addContraindicationRelationship(String drugName, String contraindication) {
        drugNodeRepository.addContraindicationRelationship(drugName, contraindication);
    }
    
    /**
     * 添加药物相互作用
     */
    public void addDrugInteraction(String drug1Name, String drug2Name, 
                                  String severity, String effect) {
        drugNodeRepository.addDrugInteraction(drug1Name, drug2Name, severity, effect);
    }
}